<?
class Tamtay_Table_Abstract extends Zend_DB_Table_Abstract
{
	public static function getMasterDB()
	{
		return Zend_Registry::get("master_db");
	}
	
	public static function getSlaveDB($key="")
	{
		$dbAdapters=Zend_Registry::get("slave_dbs");
		if ($key!="")
		{
			return $dbAdapters[$key];
		}
		$slave_key=array_rand($dbAdapters);
		return $dbAdapters[$slave_key];
	}
	
	public function execSelectQuery($sql)
	{
		$db=$this->getSlaveDB();
		$stm=$db->query($sql);
		$data=array();
		while ($obj=$stm->fetch())
		{
			$data[]=$obj;
		}
		return $data;
	}
	
	public function execScalar($sql)
	{
		$db=$this->getSlaveDB();
		return $db->fetchOne($sql);
	}
    
    protected function makeIn($ids)
    {
        $in = '';
        for ($i = 0; $i < count($ids); $i++) {
            if ($in != '') {
                $in = $in . ', ';
            }
            $in = $in . (int)$ids[$i];
        }
        return '(' . $in . ')';
    }
}

